﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * ZIP Extract Options Class
 *      Represents and manages a set of options for extracting one or more files
 * from a ZIP archive.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.IO;
using System.Collections.Generic;
using Adaptive.Foundation;

namespace Adaptive.Foundation.IO.Zip
{
    /// <summary>
    /// Represents and manages a set of options for extracting one or more files
    /// from a ZIP archive.
    /// </summary>
    public class ZipExtractOptions : DisposableObjectBase
    {
        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// Contains the list of the files to be extracted from the archive.
        /// </summary>
        private List<String> _fileNameList;
        /// <summary>
        /// Specifies the destination folder for the extracted files.
        /// </summary>
        private string _destinationPath = string.Empty;
        /// <summary>
        /// A value indicating whether to open an explorer window when the extract is complete.
        /// </summary>
        private bool _openExplorerWindow;
        /// <summary>
        /// A value indicating whether to overwrite existing files when extracting.
        /// </summary>
        private bool _overwriteExistingFiles;
        /// <summary>
        /// A value indicating whether the folder structure in the archive is to be preserved.
        /// </summary>
        private bool _useFolderNames = true;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public ZipExtractOptions()
            : base()
        {
            _fileNameList = new List<string>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipExtractOptions"/> class.
        /// </summary>
        /// <param name="destinationPath">
        /// The destination path.
        /// </param>
        public ZipExtractOptions(string destinationPath) : base()
        {
            _fileNameList = new List<string>();
            _destinationPath = destinationPath;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipExtractOptions"/> class.
        /// </summary>
        /// <param name="destinationPath">
        /// The destination path.
        /// </param>
        /// <param name="openExplorerWindow">
        /// A value indicating whether to open an explorer window when the extract is complete.
        /// </param>
        /// <param name="overwriteExistingFiles">
        /// A value indicating whether to overwrite existing files when extracting.
        /// </param>
        /// <param name="useFolderNames">
        /// A value indicating whether the folder structure in the archive is to be preserved.
        /// </param>
        public ZipExtractOptions(string destinationPath, bool openExplorerWindow, bool overwriteExistingFiles, 
            bool useFolderNames)
            : base()
        {
            _fileNameList = new List<string>();
            _destinationPath = destinationPath;

            _openExplorerWindow = openExplorerWindow;
            _overwriteExistingFiles = overwriteExistingFiles;
            _useFolderNames = useFolderNames;
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether the object is being disposed.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if ((!Disposed) && (disposing))
            {
                if (_fileNameList != null)
                    _fileNameList.Clear();
            }

            _fileNameList = null;
            _destinationPath = null;
            base.Dispose(disposing);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets the reference to the list of the files to be extracted from the archive.
        /// </summary>
        /// <value>
        /// A <see cref="T:List"/> instance containing the list of items to extract.
        /// </value>
        public List<String> FileNameList
        {
            get
            {
                return _fileNameList;
            }
        }
        /// <summary>
        /// Gets or sets the destination path.
        /// </summary>
        /// <value>
        /// A string specifying the destination path.
        /// </value>
        public string DestinationPath
        {
            get
            {
                return _destinationPath;
            }
            set
            {
                _destinationPath = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether to open an explorer window when the extract is complete.
        /// </summary>
        /// <value>
        /// <c>true</c> to open an explorer window; otherwise, <c>false</c>.
        /// </value>
        public bool OpenExplorerWindow
        {
            get
            {
                return _openExplorerWindow;
            }
            set
            {
                _openExplorerWindow = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether to overwrite existing files when extracting
        /// </summary>
        /// <value>
        /// <c>true</c> to overwrite existing files when extracting; otherwise, <c>false</c> to skip existing items.
        /// </value>
        public bool OverwriteExistingFiles
        {
            get
            {
                return _overwriteExistingFiles;
            }
            set
            {
                _overwriteExistingFiles = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the folder structure in the archive is to be preserved.
        /// </summary>
        /// <value>
        /// <c>true</c> to use the archive folder structure; otherwise, <c>false</c>.
        /// </value>
        public bool UseFolderNames        
        {
            get
            {
                return _useFolderNames;
            }
            set
            {
                _useFolderNames = value;
            }
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Public Methods / Functions
        /// <summary>
        /// Clears the contents of the object instance without disposing of the instance.
        /// </summary>
        public void Clear()
        {
            if (_fileNameList != null)
                _fileNameList.Clear();

            _destinationPath = string.Empty;
            _useFolderNames = true;
            _overwriteExistingFiles = false;
            _openExplorerWindow = false;
        }
        #endregion

    }
}
